﻿@using WebAPP.MateralUI.Helper

<button class="@ClassString" title="@Title" type="@Type" disabled="@Disabled" @onclick="OnClick">
    @ChildContent
</button>

@code {
    #region 参数
    /// <summary>
    /// 自定义Class
    /// </summary>
    [Parameter]
    public string Title { get; set; } = string.Empty;
    /// <summary>
    /// 自定义Class
    /// </summary>
    [Parameter]
    public string Class { get; set; } = string.Empty;

    /// <summary>
    /// 是否为块级按钮
    /// </summary>
    [Parameter]
    public bool IsBlock { get; set; }

    /// <summary>
    /// 类型
    /// </summary>
    [Parameter]
    public string Type { get; set; } = "button";

    /// <summary>
    /// 按钮类型
    /// </summary>
    [Parameter]
    public MButtonTypeEnum ButtonType { get; set; } = MButtonTypeEnum.Default;

    /// <summary>
    /// 按钮内部
    /// </summary>
    [Parameter]
    public RenderFragment ChildContent { get; set; }

    /// <summary>
    /// 按钮单击事件
    /// </summary>
    [Parameter]
    public EventCallback<MouseEventArgs> OnClick { get; set; }
    /// <summary>
    /// 禁用状态
    /// </summary>
    [Parameter]
    public bool Disabled { get; set; }
    #endregion
    #region 属性
    /// <summary>
    /// Class字符串
    /// </summary>
    public string ClassString
    {
        get
        {
            var result = "m_button";
            string typeClass = ButtonType.GetTargetClass();
            if (!string.IsNullOrWhiteSpace(typeClass))
            {
                result += $" {typeClass}";
            }
            if (IsBlock)
            {
                result += " m_button_block";
            }
            if (!string.IsNullOrWhiteSpace(Class))
            {
                result += $" {Class}";
            }
            return result;
        }
    }
    #endregion
}
